Skip to content

feat: Make ASGI support span first#5680

Merged
sentrivana merged 8 commits intomasterfrom
ivana/move-asgi-to-span-first
Mar 19, 2026
Merged

feat: Make ASGI support span first#5680
sentrivana merged 8 commits intomasterfrom
ivana/move-asgi-to-span-first

Conversation

@sentrivana
Copy link
Contributor

@sentrivana sentrivana commented Mar 16, 2026

This PR makes the ASGI integration work both in legacy and span streaming mode. Some features and attributes will be missing in span streaming mode for now (see the Out of scope section below).

Best reviewed with whitespace ignored: https://github.com/getsentry/sentry-python/pull/5680/changes?w=1


A bit of a background on migrating integrations to span first. In order to support both legacy spans and span streaming, most integrations will follow the same patterns:

API

We need to use the start_span API from sentry_sdk.traces if we're in span streaming mode (traces_lifecycle="stream").

There are no transactions anymore. Top-level spans will also be started via the start_span API in span streaming mode.

Setting data on spans

If an integration sets data on a span (via span.set_data, span.set_tag etc.), it should use span.set_attribute when span streaming is enabled.

The attributes that we set need to be in Sentry conventions. This is deliberately not the case for most quick ports of integrations like this one and will follow in a future step.

Trace propagation

If an integration sits at a service boundary and is capable of propagating incoming trace information (like WSGI/ASGI or Celery), in span first mode we need to switch from the old style with continue_trace(...) as transaction: to the new style continue_trace() and new_trace() (not context managers).

start_span arguments

You can pass things like op, origin, source to the old start_span API. With the new API, this is no longer possible, and the individual properties need to be set as attributes directly.

Out of scope

For now, the following is out of scope and will follow in the future:

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.85s

All tests are passing successfully.

❌ Patch coverage is 6.25%. Project has 14372 uncovered lines.

Files with missing lines (1)
File Patch % Lines
asgi.py 18.75% ⚠️ 130 Missing

Generated by Codecov Action

@sentrivana sentrivana marked this pull request as ready for review March 18, 2026 14:58
@sentrivana sentrivana requested a review from a team as a code owner March 18, 2026 14:58
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@sentrivana sentrivana merged commit e103926 into master Mar 19, 2026
158 checks passed
@sentrivana sentrivana deleted the ivana/move-asgi-to-span-first branch March 19, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants